package com.tanhua.server.controller;

import com.alibaba.fastjson.JSON;
import com.tanhua.model.domain.Conclusion;
import com.tanhua.model.domain.Report;
import com.tanhua.model.dto.SoulReportDto;
import com.tanhua.model.dto.Answers;
import com.tanhua.model.vo.ConclusionVo;
import com.tanhua.model.vo.ExamVo;
import com.tanhua.server.service.TestSoulService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testSoul")
@Slf4j
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;
    @GetMapping
    public ResponseEntity getExam(){
        List<ExamVo> examVos = testSoulService.getExam();
        return ResponseEntity.ok(examVos);
    }

    @PostMapping
    private ResponseEntity report(@RequestBody Map<String,List<SoulReportDto>> answers){
        log.info(answers+"===================================");
        String reportId = testSoulService.report(answers);
        return ResponseEntity.ok(reportId);
    }

    @GetMapping("/report/{id}")
    private ResponseEntity getReport(@PathVariable("id")int id){
        ConclusionVo conclusionVo =  testSoulService.getReport(id);
//        Map<String,String> j2map = JSON.parseObject(conclusion.getCover(), Map.class);


        return ResponseEntity.ok(conclusionVo);
    }

}
